export const crudOptions = (vm) => {
  return {
    rowHandle: {
      width: 100,
      dropdown: { // 操作列折叠
        atLeast: 0, // 至少几个以上的按钮才会被折叠,注意show=false的按钮也会计算在内（行编辑按钮默认是隐藏的也会占一个位置）
        text: '操作', // dropdown按钮文字
        type: 'primary',
        icon: 'el-icon-more'
      },
      view: {
        thin: true,
        text: '查看',
        disabled () {
          // return !vm.hasPermissions('Retrieve')
          return false
        }
      },
      edit: {
        thin: true,
        text: '编辑',
        disabled () {
          // return !vm.hasPermissions('Update')
          return false
        }
      },
      remove: {
        thin: true,
        text: '删除',
        disabled () {
          // return !vm.hasPermissions('Delete')
          return false
        }
      },
      fixed: 'right',
      custom: [{
        disabled () {
          return false
          // return !vm.hasPermissions('Update')
        },
        text: '测试',
        type: 'warning',
        icon: 'el-icon-caret-right',
        size: 'small',
        emit: 'apiTest'
      },
      {
        disabled () {
          return false
          // return !vm.hasPermissions('Update')
        },
        text: '查看结果',
        type: 'warning',
        icon: 'el-icon-s-comment',
        size: 'small',
        emit: 'showResult'
      }
      ]
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false
    },
    formOptions: { // 表单宽度
      defaultSpan: 12, // 默认的表单 span
      type: 'drawer', // 抽屉
      size: '70%'
      // width: '80%'
    },
    indexRow: { // 序号
      title: '序号',
      align: 'center',
      width: 60
    },
    selectionRow: { // 多选框
      align: 'center',
      width: 46
    },
    columns: [
      {
        title: 'Id',
        key: 'id',
        form: { // 表单配置
          disabled: true // 禁用表单编辑
        },
        // type: 'select',
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        disabled: true, // 隐藏列
        sortable: true
      },
      {
        title: '接口名称',
        key: 'name',
        // type: 'select',
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '接口名称' }],
          component: {
            span: 18,
            props: {
              clearable: true
            },
            placeholder: '请输入接口名称'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        title: '方法',
        key: 'method',
        type: 'select',
        dict: {
          data: [
            { value: 0, label: 'GET' },
            { value: 1, label: 'POST' },
            { value: 2, label: 'PUT' },
            { value: 3, label: 'DELETED' }
          ]
        },
        // search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '协议' }],
          component: {
            span: 7,
            props: {
              clearable: true
            },
            placeholder: '请输入协议'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        // title: 'URL',
        key: 'url',
        // type: 'select',
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '请输入接口地址' }],
          component: {
            span: 16,
            props: {
              clearable: true
            },
            placeholder: '请输入接口地址'
          },
          itemProps: {
            labelWidth: '0px'
          }
        },
        sortable: true
      },
      {
        title: '所属项目',
        key: 'project_belong',
        type: 'select',
        dict: {
          url: '/api/projectInfo/',
          label: 'project_name',
          value: 'id'
        },
        // dict: { url: ''}, //数据字典
        search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '所属项目' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入所属项目'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          valueChange (key, value, form, { getColumn, mode, component, immediate, getComponent }) {
            form.module_belong = undefined // 将“module_belong”的值置空
            if (value) {
              getComponent('module_belong').reloadDict() // 执行city的select组件的reloadDict()方法，触发“city”重新加载字典
            }
          }
        },
        sortable: true
      },
      {
        title: '所属模块',
        key: 'module_belong',
        type: 'select',
        dict: {
          // url: '/api/moduleInfo/',
          url (dict, { form /* 当前的form表单 */, component /* 当前的组件ref */ }) {
            if (form && form.project_belong != null) { // 本数据字典的url是通过前一个select的选项决定的
              return '/api/moduleInfo/?project_belong=' + form.project_belong
            } else {
              return '/api/moduleInfo/'
            }
          },
          label: 'module_name',
          value: 'id'
        },
        // dict: { url: ''}, //数据字典
        search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '所属模块' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入所属模块'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        title: '参数类型',
        key: 'params_type',
        type: 'radio',
        dict: {
          data: vm.dictionary('params_type')
        },
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          value: 0,
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '参数类型' }],
          component: {
            span: 14,
            props: {
              clearable: true,
              type: 'el-radio-button'
            },
            placeholder: '请输入参数类型'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        title: '头部信息',
        key: 'headers',
        type: 'textarea',
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          // rules: [{ required: true, message: '头部信息' }],
          component: {
            span: 20,
            show (context) {
              return context.form.params_type === 0
            },
            showWordLimit: true,
            maxlength: '200',
            props: {
              clearable: true,
              type: 'textarea'
            },
            placeholder: '请输入头部信息'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          helper: {
            render (h) {
              return (< el-alert title="json数据格式" type="warning" />
              )
            }
          }
        },
        sortable: true
      },
      {
        title: '普通参数',
        key: 'params',
        type: 'textarea',
        showOverflow: true,
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          // rules: [{ required: true, message: '普通参数' }],
          component: {
            span: 20,
            show (context) {
              return context.form.params_type === 1
            },
            showWordLimit: true,
            maxlength: '200',
            props: {
              clearable: true,
              type: 'textarea'
            },
            placeholder: '请输入普通参数'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          helper: {
            render (h) {
              return (< el-alert title="userName=admin&password=1234数据格式" type="warning" />
              )
            }
          }
        },
        sortable: true
      },
      {
        title: 'json参数',
        key: 'jsonbody',
        type: 'textarea',
        showOverflow: true,
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          // rules: [{ required: true, message: 'json参数' }],
          component: {
            span: 20,
            show (context) {
              return context.form.params_type === 2
            },
            showWordLimit: true,
            maxlength: '200',
            props: {
              clearable: true,
              type: 'textarea'
            },
            placeholder: '请输入json参数'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          helper: {
            render (h) {
              return (< el-alert title="输入json格式数据" type="warning" />
              )
            }
          }
        },
        sortable: true
      },
      {
        title: '检查点',
        key: 'verification',
        showOverflow: true,
        // type: 'select',
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          // rules: [{ required: true, message: '检查点' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入检查点'
          },
          itemProps: {
            // class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        title: '关联',
        key: 'extract',
        showOverflow: true,
        // type: 'select',
        // dict: { url: ''}, //数据字典
        // search: { disabled: false }, // 开启查询
        // disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          // rules: [{ required: true, message: '关联' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入关联'
          },
          itemProps: {
            // class: { yxtInput: true }
          }
        },
        sortable: true
      }

    ].concat(vm.commonEndColumns(
      {
        create_datetime: { showTable: false },
        update_datetime: { showTable: false }
      }
    ))
  }
}
